package com.nnnu.orange.controller.user;


import com.nnnu.orange.constant.MessageConstants;
import com.nnnu.orange.constant.StatusCodeConstants;
import com.nnnu.orange.pojo.dto.BookDto;
import com.nnnu.orange.pojo.dto.BooksQueryDto;
import com.nnnu.orange.pojo.entity.Books;
import com.nnnu.orange.pojo.vo.BooksInfoVo;
import com.nnnu.orange.result.PageResult;
import com.nnnu.orange.result.Result;
import com.nnnu.orange.service.IBooksService;
import com.nnnu.orange.utils.ExcelParser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;

/**
 * <p>
 * 存储每本图书的详细信息 前端控制器
 * </p>
 *
 * @author zk
 * @since 2024-11-07
 */
@RestController("userBooksController")
@RequestMapping("/user/books")
@RequiredArgsConstructor
@Api(tags = "用户端图书相关接口")
@Slf4j
public class BooksController {

    private final IBooksService iBooksService;

    /**
     * 分页查询图书列表
     *
     * @param queryDto dto
     * @return 返回前端数据 分页图书列表
     */
    @GetMapping("/list")
    @ApiOperation("分页查询图书列表")
    public Result<?> listBooks(BooksQueryDto queryDto) {
        log.info("分页查询图书列表:{}", queryDto);
        return Result.success(iBooksService.listBooks(queryDto), MessageConstants.SELECT_OK);
    }


    /**
     * 获取单本图书的详细信息
     *
     * @param id 图书id
     * @return 返回前端图书实体
     */
    @ApiOperation("获取单本图书的详细信息")
    @GetMapping("/{id}")
    public Result<Books> getOne(@PathVariable Integer id) {
        log.info("获取单本图书的详细信息:{}", id);
        return Result.success(iBooksService.getById(id), MessageConstants.SELECT_OK);
    }
}
